<?php
// 获取报修类型信息
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");
if(empty($_GET['searchtype'])){
    $sql = "SELECT * FROM tb_fix_leave ORDER BY leave_num ASC";
}else{
    $type_name = $_GET['typename'];
    $sql = "SELECT * FROM tb_fix_leave WHERE leave_name = '$type_name'";
}

$result = mysqli_query($conn_DB,$sql);
if($result){
    if(empty($_GET['searchtype'])){
        $c = 0;
        while($row = mysqli_fetch_object($result)){
            if($c % 4 == 0){
                echo"<div class='type-div'>";
            }
            if($row->leave_num == '1'){
                $l = "一级故障";
                $class = "leave_1";
            }
            if($row->leave_num == '2'){
                $l = "二级故障";
                $class = "leave_2";
            }
            if($row->leave_num == '3'){
                $l = "三级故障";
                $class = "leave_3";
            }
            echo"<div class='type-div-item'>
                    <div class='type-div-item-title'><b>".$row->leave_name."</b></div>
                    <div class='type-div-item-leave ".$class."'>".$l."</div>
                    <div class='type-div-item-time'>最近更新：".$row->update_time."</div>
                </div>";
            $c++;    
            if($c % 4 == 0){
                echo"</div>";
            }
        }
    }else{
        $row = mysqli_fetch_object($result);
        if($row->leave_num == '1'){
            $option="<option value='1' selected>一级故障</option>
                <option value='2'>二级故障</option>
                <option value='3'>三级故障</option>";
        }
        if($row->leave_num == '2'){
            $option="<option value='1'>一级故障</option>
                <option value='2' selected>二级故障</option>
                <option value='3'>三级故障</option>";
        }
        if($row->leave_num == '3'){
            $option="<option value='1'>一级故障</option>
                <option value='2'>二级故障</option>
                <option value='3' selected>三级故障</option>";
        }
        echo"
            <form class='row g-3' action='php/deal-tasks.php' method='post'>
                <input type='hidden' name='leave_id' value='".$row->id."'>
                <input type='hidden' name='action' value='leave_change'>
                <div class='mb-3'>
                    <label for='leave_name' class='form-label'>故障类型名称</label>
                    <input type='text' class='form-control' id='leave_name' name='leave_name' value='".$row->leave_name."' required>
                </div>
                <div class='col-md-4'>
                    <label for='leave_num' class='form-label '>故障类型等级</label>
                    <select name='leave_num' id='leave_num' class='form-select'>
                        ".$option."
                    </select>
                </div>
                <div class='btn-div'>
                    <button type='submit' class='btn btn-primary sub-btn-style'  onclick='return checkType()'>提交修改</button>
                </div>
            </form>
        ";
    }
}